package com.kongqw.wechathelper

import android.content.Context
import com.kongqw.wechathelper.net.IBaseRequest
import com.kongqw.wechathelper.utils.Logger

class WeChatHelper private constructor(context: Context) : WeChatBaseHelper(context) {

    companion object {
        var IS_LOGGABLE: Boolean = false
        var mRequest: IBaseRequest? = null

        @Volatile
        private var instance: WeChatHelper? = null

        @JvmStatic
        fun getInstance(context: Context) =
            instance ?: synchronized(this) {
                instance ?: WeChatHelper(context).also { instance = it }
            }
    }

    fun init(isLoggable: Boolean, request: IBaseRequest? = null): Boolean {
        IS_LOGGABLE = isLoggable
        mRequest = request

        // 将应用的appId注册到微信
        val isInitWeChat = api.registerApp(mWeChatAppId)
        Logger.d("isInitWeChat = $isInitWeChat  mWeChatAppId = $mWeChatAppId")

        return true
    }

    fun setRequestClient(request: IBaseRequest) {
        if (mRequest == null) mRequest = request
    }

}